<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>添加素材分组</title>
    <link rel="stylesheet" href="../assets/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="../assets/style/admin.css">
</head>
<body class="layui-layout-body">
<div class="layui-layout layui-layout-admin">
    <script src="../common/header.js"></script>
    <!-- 内容主体区域 -->
    <div id="LAY_app_body">
        <div class="layui-fluid">
            <div class="layui-row layui-col-space15">
                <div class="layui-col-md12">
                    <div class="layui-card">
                        <div class="layui-card-header">添加素材分组</div>
                        <div class="layui-card-body">
                            <form class="layui-form layui-form-pane" action="">
                                <div class="layui-form-item">
                                    <div class="layui-inline">
                                        <label class="layui-form-label">分组名</label>
                                        <div class="layui-input-inline">
                                            <input type="text" name="name" lay-verify="name" autocomplete="off"
                                                   placeholder="请输入分组名" value="" class="layui-input">
                                        </div>
                                    </div>
                                </div>
                                <div class="layui-form-item">
                                    <label class="layui-form-label">选择分类</label>
                                    <div class="layui-input-inline">
                                        <select id="type" name="type" lay-verify="type" style="layui-input-inline"
                                                onchange="reloadList()">
                                            <option value="0">选择分类</option>
                                            <option value="1">昵称</option>
                                            <option value="2">头像</option>
                                            <option value="3">朋友圈背景</option>
                                            <option value="4">个性签名</option>
                                            <option value="5">自动回复</option>
                                            <option value="6">聊天话术</option>
                                        </select>
                                    </div>
                                </div>
                                <div class="layui-form-item">
                                    <div class="layui-input-block">
                                        <a class="layui-btn" lay-submit lay-filter="formSubmit">提交</a>
                                        <a class="layui-btn layui-btn-primary" href="material_group_manage.html">取消</a>
                                    </div>
                                </div>
                            </form>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <script>
        layui.use(['form', 'layer'], function () {
            var $ = layui.$
                , form = layui.form
                , layer = layui.layer

            form.verify({
                name: function (value) {
                    if (value.length < 1) {
                        return '请输入分组名';
                    }
                },
                type: function (value) {
                    if (value === '0') {
                        return '请选择分组';
                    }
                }
            });
            //监听提交
            form.on('submit(formSubmit)', function (data) {
                layer.msg('提交中', {
                    shadeClose: false
                    , icon: 16
                    , shade: 0.01
                });
                service.post('api/v1/materialgroup', {
                    name: data.field.name,
                    type: parseInt(data.field.type)
                }).then((response) => {
                    if (response.code === 200) {
                        //添加成功
                        layer.msg('添加成功', {offset: '45vh', icon: 1, time: 2000});
                    } else {
                        layer.msg(response.msg, {offset: '45vh', icon: 5, time: 2000});
                    }
                }).catch((err) => {
                    layer.msg(err.msg, {offset: '45vh', icon: 5, time: 2000});
                })
            })
        });
    </script>
</div>
</body>
</html>
